import { defineStore } from "pinia";
import { reqTrade, reqSubmitOrder } from '../api/trade/trade'
import { ref } from "vue";
//使用路由

export const getTradeStore = defineStore("TradeStore", () => {
    let TradeData = ref<any>({})
    let userAddressList = ref<any>([])//地址列表
    let detailArrayList = ref<any>([])//提交订单要用的商品清单
    let totalAmount = ref<any>('')//条数
    let tradeNo = ref<any>('')//提交订单要用的订单号
    let submitData = ref<any>('')//提交订单返回的数据
    let submitCode = ref<any>({})//提交订单返回的数据
    const reqTradeData = async () => {
        let result: any = await reqTrade()
        console.log(result);
        TradeData.value = result
        userAddressList.value = result.data.userAddressList
        detailArrayList.value = result.data.detailArrayList
        totalAmount.value = result.data.totalAmount
        tradeNo.value = result.data.tradeNo
    }
    const submit = async (tradeNo: any, data: any) => {
        let result: any = await reqSubmitOrder(tradeNo, data)
        submitCode.value = result.code
        submitData.value = result.data
    }

    return { reqTradeData, submit, TradeData, userAddressList, detailArrayList, totalAmount, tradeNo, submitData }
})